	.module adc.c
	.area text(rom, con, rel)
	.dbfile D:\01.Projects\JKElectronics\ATMEGA\CoreModule\sw\examples\lib\adc.c
	.dbfunc e bsp_adc_gpio_init _bsp_adc_gpio_init fV
;        channel -> R16
	.even
_bsp_adc_gpio_init::
	.dbline -1
	.dbline 6
; 
; #include "hw_config.h"
; #include "adc.h"
; 
; void bsp_adc_gpio_init(bsp_adc_channel_define_type channel) 
; {
	.dbline 7
; 	if( channel == adChannel0 )
	tst R16
	brne L5
X0:
	.dbline 8
; 	{
	.dbline 9
; 		cbi(ADC_CH0_DDR, ADC_CH0_PIN_NO);
	lds R24,97
	andi R24,254
	sts 97,R24
	.dbline 10
; 		cbi(ADC_CH0_PORT, ADC_CH0_PIN_NO);
	lds R24,98
	andi R24,254
	sts 98,R24
	.dbline 11
; 	}
	xjmp L6
L5:
	.dbline 12
; 	else if( channel == adChannel1 )
	cpi R16,1
	brne L7
X1:
	.dbline 13
; 	{
	.dbline 14
; 		cbi(ADC_CH1_DDR, ADC_CH1_PIN_NO);
	lds R24,97
	andi R24,253
	sts 97,R24
	.dbline 15
; 		cbi(ADC_CH1_PORT, ADC_CH1_PIN_NO);
	lds R24,98
	andi R24,253
	sts 98,R24
	.dbline 16
; 	}	
L7:
L6:
	.dbline -2
L4:
	.dbline 0 ; func end
	ret
	.dbsym r channel 16 c
	.dbend
	.dbfunc e adc_get_value _adc_get_value fi
;          adc_h -> R12
;          adc_l -> R10
;            ret -> R10,R11
;        channel -> R20
	.even
_adc_get_value::
	xcall push_xgset303C
	mov R20,R16
	.dbline -1
	.dbline 20
; }
; 
; u16 adc_get_value(bsp_adc_channel_define_type channel) 
; { 
	.dbline 24
; 	u16 ret; 
; 	byte adc_l, adc_h; 
; 	
; 	ADCSRA=0x00;    
	clr R2
	out 0x6,R2
	.dbline 27
; 
; 	// AVCC with external capacitor
; 	ADMUX=0x40 |channel;    // channel select
	mov R24,R20
	ori R24,64
	out 0x7,R24
	.dbline 30
; 	
; 	// ADC Enable | Conversion Start | Free running Mode | 128 Division
; 	ADCSRA = (1<<ADEN) |(1<<ADSC) | (1<<ADFR) | (1<<ADPS2) | (1<<ADPS1) | (1<<ADPS0);
	ldi R24,231
	out 0x6,R24
	.dbline 32
; 	
; 	_delay_ms(5);         	// delay
	ldi R16,5
	ldi R17,0
	xcall __delay_ms
	.dbline 34
; 	
; 	adc_l  = ADCL;   		// get low value
	in R10,0x4
	.dbline 35
; 	adc_h = ADCH;   		// get high valueλֵ
	in R12,0x5
	.dbline 37
; 	
; 	ret = (adc_h<<8) | adc_l;  // ADC voltage value
	mov R11,R12
	.dbline 39
; 	
; 	return(ret); // return value of the voltage measured
	movw R16,R10
	.dbline -2
L9:
	.dbline 0 ; func end
	xjmp pop_xgset303C
	.dbsym r adc_h 12 c
	.dbsym r adc_l 10 c
	.dbsym r ret 10 i
	.dbsym r channel 20 c
	.dbend
; 	
; } 
